import { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { Datum, fetchSolutionDetailAPI } from '@/apis/solutionDetail'
// import { log } from 'console'

function useSolution() {
  // 标题
//   const [headers, setHeaders] = useState<HeaderItem["caption"]>()
  // 图片
  const [detailData, setImgs] = useState<Datum>({})
  const params = useParams()
  const id = params.id
  // console.log(id);
  
  useEffect(() => {
    const getSolutionDetail = async () => {
      try {
        const res = await fetchSolutionDetailAPI({id})
        console.log(res);
        // setHeaders(res.data.head[0].caption)
        setImgs(res.data.data[0])
      } catch (error) {
        throw new Error('fetch SolutionDetail error')
      }
    }
    getSolutionDetail()
  }, [])
  // 暴露数据
  return {
    detailData
  }
}

export { useSolution }
